home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 05 / 6 / DISK0564.ZIP / SOURCE.ARC / B.ARC / FSEARCH.C < prev    next >
C/C++ Source or Header  |  1986-04-09  |  2KB  |  85 lines

  1. /* DOS-specific routines to search for files matching a file specification */
  2. /* ? and * wildcards are supported */
  3. /* for Manx Aztec C86, v. 3.2 */
  4. /* by Jon Dart, 03-Mar-86 */
  5. /* modified 09-Apr-86 */
  6.  
  7. /* Note: DS = ES (small data model) is assumed */
  8.  
  9. static char *buf;
  10.  
  11. struct regstruc {
  12.     unsigned int ax,bx,cx,dx,si,di;
  13. } inregs,outregs,temp;
  14.  
  15. extern unsigned int doscall();
  16. extern char *cpycnt();
  17. extern char *malloc();
  18.  
  19. putfn(filename,attrib)
  20. char *filename; int *attrib;
  21. /* called by getfirst & getnext, unpacks file name from buf into filename
  22.    and sets attrib to file attribute */
  23. {
  24.     int n;
  25.     char *p;
  26.     int *pa;
  27.  
  28.     pa = (int *)(buf+21);
  29.     *attrib =  *pa;
  30.     p = (char *) (buf+30);
  31.     n = 12;
  32.     filename = cpycnt(p,filename,&n);
  33. }
  34.  
  35. getfirst(filespec,inattrib,filename,outattrib)
  36. /* search for file matching 'filespec' and having attributes 'attrib'.
  37.    returns 0 if no match, else returns <>0 and filename found, also
  38.    sets attrib to attributes of file found */
  39. char *filespec, *filename;
  40. int inattrib; int *outattrib;
  41. {
  42.     char *p;
  43.     int *pa;
  44.  
  45.     buf = malloc(128); /* allocate buffers space */
  46.     doscall(0x2F,&inregs,&outregs); /* get current DTA */
  47.     temp.dx = outregs.bx; /* save DTA in dx */
  48.     inregs.dx = (int) buf;
  49.     doscall(0x1A,&inregs,&outregs); /* set DTA to buf */
  50.     inregs.dx = (int) filespec; inregs.cx = inattrib;
  51.     if (doscall(0x4E,&inregs,&outregs)==0) {
  52.         doscall(0x1A,&temp,&outregs); /* reset DTA */
  53.         putfn(filename,outattrib);
  54.         return(1);
  55.     }
  56.     else { /* no file */
  57.         free(buf);
  58.         doscall(0x1A,&temp,&outregs); /* reset DTA */
  59.         return(0);
  60.     }
  61. }
  62.  
  63. getnext(filename,attrib)
  64. /* search for next file (assumes previous call to getfirst).
  65.    returns 0 if no match, else returns <>0, filename found, and
  66.    its attribute */
  67. char *filename; int *attrib;
  68. {
  69.     doscall(0x2F,&inregs,&outregs); /* get current DTA */
  70.     temp.dx = outregs.bx; /* save DTA in dx */
  71.     inregs.dx = (int) buf;
  72.     doscall(0x1A,&inregs,&outregs); /* set DTA to buf */
  73.     if (doscall(0x4F,&inregs,&outregs)==0) {
  74.         putfn(filename,attrib);
  75.         doscall(0x1A,&temp,&outregs); /* restore DTA */
  76.         return(1);
  77.     }
  78.     else { /* no file */
  79.         free(buf);
  80.         doscall(0x1A,&temp,&outregs); /* restore DTA */
  81.         return(0);
  82.     }
  83. }
  84.  
  85.